package com.yumeng.webapp.shiro.config;

import com.yumeng.doc.config.SpringDocConfiguration;
import io.swagger.v3.oas.models.ExternalDocumentation;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Contact;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import lombok.extern.slf4j.Slf4j;
import org.springdoc.core.models.GroupedOpenApi;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * SpringDoc配置文件
 *
 * @author wxd
 * @date 2025/9/19 20:18
 */
@Slf4j
@Configuration
public class SpringDocConfig extends SpringDocConfiguration {

    @Bean
    public OpenAPI customOpenAPI() {
        return new OpenAPI()
                .info(new Info()
                        .title("yumeng-shiro-Demo")
                        .version("1.2")
                        .description( "yumeng shiro APIs示例")
                        .termsOfService("http://www.yumeng.com")
                        .license(new License().name("Apache 2.0")
                                .url("http://www.yumeng.com"))
                        .contact(new Contact()
                                .name("ddz")
                                .email("664632213@qq.com")))
                .externalDocs(new ExternalDocumentation()
                        .description("ddzDocs")
                        .url("https://ddzDocs.top"));
        //全局添加鉴权 待研究
/*                .addSecurityItem(new SecurityRequirement().addList(HttpHeaders.AUTHORIZATION))
                .components(new Components().addSecuritySchemes(HttpHeaders.AUTHORIZATION,new SecurityScheme()
                        .name(HttpHeaders.AUTHORIZATION).type(SecurityScheme.Type.HTTP).scheme("bearer")));*/
    }

    //TODO 如何实现按接口名后缀过滤，比如仅显示.do结尾的接口
    @Bean
    public GroupedOpenApi userApi(){
        String[] paths = { "/**" };
        String[] packagedToMatch = {"com.yumeng"};
        return GroupedOpenApi.builder().group("yumeng")
                .displayName("yumeng-shiro文档")
                .pathsToMatch(paths)
/*                .addOpenApiMethodFilter(p->{
                    String aa = p.getName();
                    return true;
                })*/
/*                .addOperationCustomizer((operation, handlerMethod) ->
                        operation.addParametersItem(
                                new HeaderParameter().name("groupCode").example("测试").description("集团code")
                                .schema(new StringSchema()._default("BR2").name("groupCode2").description("集团code2"))
                        )
                )*/
                .packagesToScan(packagedToMatch).build();
    }

}
